package com.zhf.servlet.class1;

import com.zhf.exception.MyException;
import com.zhf.service.ClassService;
import com.zhf.service.impl.ClassServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ClassDeleteServlet" , urlPatterns = "/classDelete")
public class ClassDeleteServlet extends HttpServlet {
    ClassService classService = new ClassServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String[] classNos = request.getParameterValues("classNo");
        try{
            boolean isDelete = classService.deleteClass(classNos);
            if(isDelete){
                request.setAttribute("msg", "删除成功");
                request.setAttribute("code", "100");
            }
        }
        catch (MyException e){
            request.setAttribute("msg", e.getMessage());
            request.setAttribute("code", e.getCode());
        }
        request.getRequestDispatcher("/classQueryAll").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
